<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JSX列表渲染</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/react/18.2.0/umd/react.development.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js"></script>
  <!-- 引入 babel -->
  <script src="https://cdn.bootcdn.net/ajax/libs/babel-standalone/7.19.2/babel.min.js"></script>
</head>
<body>
<div id="root"></div>

<!-- 设置js代码被babel处理 -->
<script type="text/babel">
  const data = ['孙悟空', '猪八戒', '沙和尚'];
  // const arr = [];
  // for (let i = 0; i < data.length; i++) {
  //   arr.push(<li key={i} className={i}>{data[i]}</li>);
  // }
  // const list = <ul>{arr}</ul>;
  const list = <ul>{data.map(item=><li key={item}>{item}</li>)}</ul>;
  const root = ReactDOM.createRoot(document.getElementById('root'));
  root.render(list);
</script>
</body>
</html>